(function( $ ) {
	$.fn.rateBox = function(options) {
		var settings = $.extend( {
				'star_class'       : 'cf-rating-star',
				'number_of_stars'  : 5,
				'rating'           : 5,
				'onRate'           : function() { }
			}, options);
	
		for (var i=0; i<settings.number_of_stars; ++i) {
			this.append( $('<a>')
				.attr('href','#')
				.addClass('cf-rating-star').toggleClass('selected',i<settings.rating)
				.on( {
					'click': function(i) { return function(e){ e.preventDefault(); settings.rating=i+1; settings.onRate(i+1); }; }(i),
					'mouseover': function(o,i) { return function(e) {
							o.children('a:lt('+(i+1)+')').addClass('selected');
							o.children('a:gt('+i+')').removeClass('selected');
						} }(this,i),
					'mouseout': function(o) { return function(e) {
						o.children('a:lt('+settings.rating+')').addClass('selected'); 
						o.children('a:gt('+(settings.rating-1)+')').removeClass('selected'); 
					} }(this)
				})
			);
		}
		return this;
	};
})( jQuery );